<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yang-da-xiong.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="前言本篇主要记录自己配置OpenCV4的步骤和心得。IDE为Visual Studio2017，OpenCV版本号为4.5.5 目前opencv4系列主要支持vs2015和vs2017两个版本，这里推荐还是将vs版本更新到上述两个版本之一，以免出现配置上的兼容问题。 配置主要分为6个步骤：1）下载和安装OpenCV SDK  2）配置包含路径   3）配置库目录  4）配置链接器  5）配置环境变">
<meta property="og:type" content="article">
<meta property="og:title" content="OpenCV配置教程">
<meta property="og:url" content="https://yang-da-xiong.gitee.io/2022/01/29/OpenCV%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/index.html">
<meta property="og:site_name" content="杨大熊的代码世界">
<meta property="og:description" content="前言本篇主要记录自己配置OpenCV4的步骤和心得。IDE为Visual Studio2017，OpenCV版本号为4.5.5 目前opencv4系列主要支持vs2015和vs2017两个版本，这里推荐还是将vs版本更新到上述两个版本之一，以免出现配置上的兼容问题。 配置主要分为6个步骤：1）下载和安装OpenCV SDK  2）配置包含路径   3）配置库目录  4）配置链接器  5）配置环境变">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/411c86ee09db4499b855d4cfc4f392f6.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c644e716c7f74326b0092efb98119666.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/7734b53d948b495db549f20148326cf5.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/059ae7adfd9a41b492420f357557300c.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c4186170cd0840358864ea138f2ca896.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/60de24971c9444e8a575c015ce6522a3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/839b31a601b4475e89dfae8a18e3d214.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/dfcf295179354579b1cb6d89e88651d8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/7caace795c234bad8b7b16d249ffdca2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/d62c7628f994467289e84be686b9eaca.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c15af10bec1e49448e9a02a6010ac52f.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/9e8397b2345540eaa61b9275fccb18a7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/5d704fac599046eda7438d356584a011.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/121247433280481197a902ea4c656ccc.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/420bd9699cca48b780704a58205ad3bb.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_11,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/029ca1bc28804e1492bb432b02321e05.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/91a15925d2514137848fcfbac37ee1e2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/3634e97a38784e628ce05c1b76d1cfd6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/0815fcab5c534e6e82d3de587b32c5e0.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/581775de68e14fc09104d5fc6b5497c6.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/af53b8ce0d3b491488e5db14f990b788.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_17,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/8a481eb9c9624f1c9087add6f60d3fd7.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/850594ac4e674b05851af91592909d0f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/cb91498c3435444396ebaddbdc3a7f86.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c8d49ee21af540318e3891ce912d3b77.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_11,color_FFFFFF,t_70,g_se,x_16">
<meta property="og:image" content="https://img-blog.csdnimg.cn/4b520eb643ad4b9098890f39b90493aa.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16">
<meta property="article:published_time" content="2022-01-29T04:02:40.249Z">
<meta property="article:modified_time" content="2022-01-29T07:01:21.414Z">
<meta property="article:author" content="杨大熊">
<meta property="article:tag" content="Opencv">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/411c86ee09db4499b855d4cfc4f392f6.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">

<link rel="canonical" href="https://yang-da-xiong.gitee.io/2022/01/29/OpenCV%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>OpenCV配置教程 | 杨大熊的代码世界</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">杨大熊的代码世界</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://yang-da-xiong.gitee.io/2022/01/29/OpenCV%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="杨大熊">
      <meta itemprop="description" content="各类IT知识分享">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="杨大熊的代码世界">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          OpenCV配置教程
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2022-01-29 12:02:40 / 修改时间：15:01:21" itemprop="dateCreated datePublished" datetime="2022-01-29T12:02:40+08:00">2022-01-29</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%86%E8%A7%89/" itemprop="url" rel="index"><span itemprop="name">计算机视觉</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>本篇主要记录自己配置OpenCV4的步骤和心得。IDE为Visual Studio2017，OpenCV版本号为4.5.5</p>
<p>目前opencv4系列主要支持vs2015和vs2017两个版本，这里推荐还是将vs版本更新到上述两个版本之一，以免出现配置上的兼容问题。</p>
<p>配置主要分为6个步骤：1）下载和安装OpenCV SDK  2）配置包含路径   3）配置库目录  4）配置链接器  5）配置环境变量  6）dll文件复制到system32中</p>
<p>下面开始具体介绍</p>
<span id="more"></span>

<h1 id="一、下载和安装OpenCV-SDK"><a href="#一、下载和安装OpenCV-SDK" class="headerlink" title="一、下载和安装OpenCV SDK"></a>一、下载和安装OpenCV SDK</h1><p>在opencv官网下载相关安装包即可</p>
<p>附官网下载链接：<a target="_blank" rel="noopener" href="https://opencv.org/releases/">Releases - OpenCV</a> </p>
<p>点击realease</p>
<img src="https://img-blog.csdnimg.cn/411c86ee09db4499b855d4cfc4f392f6.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="80%">



<p>选择对应的操作系统，这里我选择的Windows，版本为4.5.5</p>
<p><img src="https://img-blog.csdnimg.cn/c644e716c7f74326b0092efb98119666.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<img src="https://img-blog.csdnimg.cn/7734b53d948b495db549f20148326cf5.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="80%">



<p>下载完成后，运行点击解压</p>
<p><img src="https://img-blog.csdnimg.cn/059ae7adfd9a41b492420f357557300c.png" alt="在这里插入图片描述"></p>
<p>这里我新建了一个opencv4的文件夹，为了和之前安装的其他版本的opencv重叠。</p>
<p><img src="https://img-blog.csdnimg.cn/c4186170cd0840358864ea138f2ca896.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>解压完成后，如果出现以上内容，就说明解压成功了，其中build文件夹是主要的OpenCV相关文件，里面含有头文件与库文件等重要信息，接下来的环境配置工作都要围绕其展开。</p>
<h1 id="二、配置包含路径"><a href="#二、配置包含路径" class="headerlink" title="二、配置包含路径"></a>二、配置包含路径</h1><p>这一步主要完成的工作是告诉计算机安装的OpenCV在哪里，以及告诉IDE应该去哪里找到头文件与库文件。</p>
<p>我们先在vs2017中创建一个新的空项目</p>
<p><img src="https://img-blog.csdnimg.cn/60de24971c9444e8a575c015ce6522a3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>新建一个源文件</p>
<p><img src="https://img-blog.csdnimg.cn/839b31a601b4475e89dfae8a18e3d214.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>起名为main.cpp</p>
<p><img src="https://img-blog.csdnimg.cn/dfcf295179354579b1cb6d89e88651d8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>然后我们将Debug模式改为对应的x64模式</p>
<p><img src="https://img-blog.csdnimg.cn/7caace795c234bad8b7b16d249ffdca2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>然后点击视图中的其他窗口，打开属性管理器</p>
<img src="https://img-blog.csdnimg.cn/d62c7628f994467289e84be686b9eaca.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="70%">

<p>双击红色箭头所指选项：</p>
<p><img src="https://img-blog.csdnimg.cn/c15af10bec1e49448e9a02a6010ac52f.png" alt="在这里插入图片描述"></p>
<p>打开后，点击<strong>包含目录</strong>的红色箭头所指的编辑位置</p>
<p><img src="https://img-blog.csdnimg.cn/9e8397b2345540eaa61b9275fccb18a7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>点击＋号</p>
<img src="https://img-blog.csdnimg.cn/5d704fac599046eda7438d356584a011.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="70%">

<p>将刚才解压的opencv文件中build的两个相关的子文件夹添加到包含目录中，分别是bulid\include和build\include\opencv2</p>
<h1 id="三、配置库目录-amp-配置链接器"><a href="#三、配置库目录-amp-配置链接器" class="headerlink" title="三、配置库目录&amp;配置链接器"></a>三、配置库目录&amp;配置链接器</h1><p><strong>库目录</strong>的配置和<strong>包含目录</strong>的操作步骤类似，不过这里要说明的是，如果vs版本为2017，则选择<strong>vc15</strong>，如果vs版本为2015，则选择<strong>vc14</strong>。</p>
<p><img src="https://img-blog.csdnimg.cn/121247433280481197a902ea4c656ccc.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>路径如图所示</p>
<p><img src="https://img-blog.csdnimg.cn/420bd9699cca48b780704a58205ad3bb.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_11,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>下面配置链接器：</p>
<p>点击链接器中的输入选项，在附加依赖项中新添信息</p>
<p><img src="https://img-blog.csdnimg.cn/029ca1bc28804e1492bb432b02321e05.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>新添的信息为opencv_world455d.lib，world后面的数字与具体的版本号有关，大家需要去刚才库目录的lib文件夹下查看自己的world号进行设置</p>
<p><img src="https://img-blog.csdnimg.cn/91a15925d2514137848fcfbac37ee1e2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>在lib文件夹下，有两个lib文件，一个以d结尾，一个没有，含有“d”的lib文件是在Debug模式下使用，就是我们现在创建的模式，而不含“d”的文件在Release模式下使用，配置该模式时再使用，这里我们选择带“d”的文件。</p>
<p><img src="https://img-blog.csdnimg.cn/3634e97a38784e628ce05c1b76d1cfd6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<h1 id="四、配置环境变量"><a href="#四、配置环境变量" class="headerlink" title="四、配置环境变量"></a>四、配置环境变量</h1><p>上述步骤主要负责告诉vs2017去哪里寻找我们的opencv，而环境变量则是告诉计算机去哪里寻找opencv</p>
<p><img src="https://img-blog.csdnimg.cn/0815fcab5c534e6e82d3de587b32c5e0.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>在Windows搜索栏输入环境变量，打开环境变量</p>
<img src="https://img-blog.csdnimg.cn/581775de68e14fc09104d5fc6b5497c6.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="60%">

<p>点击后，在系统变量中找到Path，然后点击编辑</p>
<p><img src="https://img-blog.csdnimg.cn/af53b8ce0d3b491488e5db14f990b788.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_17,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>新建一个路径，具体的值如图所示，配置完成后点击确定</p>
<img src="https://img-blog.csdnimg.cn/8a481eb9c9624f1c9087add6f60d3fd7.png?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzIwMTc3MzI3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" width="70%">

<h1 id="五、dll文件复制到system32中"><a href="#五、dll文件复制到system32中" class="headerlink" title="五、dll文件复制到system32中"></a>五、dll文件复制到system32中</h1><p>在上述工作完成后，我们只差最后一步了，我们把bin目录下的所有.dll文件复制一下，放到C:\Windows\System32中</p>
<p><img src="https://img-blog.csdnimg.cn/850594ac4e674b05851af91592909d0f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>将这个5个dll文件复制后，放到C:\Windows\System32中（.dll文件数量随版本不同而不同，老版本一般为3个dll左右）</p>
<p><img src="https://img-blog.csdnimg.cn/cb91498c3435444396ebaddbdc3a7f86.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>以上所有步骤完成后，就大功告成啦！</p>
<h1 id="六、验证配置结果"><a href="#六、验证配置结果" class="headerlink" title="六、验证配置结果"></a>六、验证配置结果</h1><p>配置完成后，我们调用opencv的一个显示图像功能来验证一下opencv是否已经成功配置，要显示的图像是非常经典的lena美女：</p>
<p><img src="https://img-blog.csdnimg.cn/c8d49ee21af540318e3891ce912d3b77.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_11,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>我们在刚才的项目中，粘贴以下代码，注意图片的位置要根据<strong>实际的图片位置</strong>来填写</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;opencv2\opencv.hpp&gt;</span>  <span class="comment">//加载OpenCV4的头文件</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> cv; <span class="comment">//OpenCV命名空间</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	Mat img;  <span class="comment">//声明一个保存图像的类</span></span><br><span class="line">	img = imread(<span class="string">&quot;D:/vs c++小练习/opencv4_test/opencv4_test/lena.jpg&quot;</span>);  <span class="comment">//读取图像，图像的位置要按实际位置填写</span></span><br><span class="line">	<span class="keyword">if</span> (img.empty())  <span class="comment">//判断图像文件是否存在</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;请确认图像文件名是否正确&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	imshow(<span class="string">&quot;test&quot;</span>, img); <span class="comment">//显示图像</span></span><br><span class="line">	waitKey(<span class="number">0</span>);  <span class="comment">//等待键盘输入</span></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;  <span class="comment">//程序结束</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>程序的正确运行结果如下：</p>
<p><img src="https://img-blog.csdnimg.cn/4b520eb643ad4b9098890f39b90493aa.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5p2o5aSn54aK55qE5Luj56CB5LiW55WM,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>可以看到，我们的程序成功打开了美女lena的图片，当然这张经典的图片也是部分截取而来，完整的全图发个链接：<a target="_blank" rel="noopener" href="http://www.lenna.org/full/l_hires.jpg">http://www.lenna.org/full/l_hires.jpg</a> ，只能说，懂得都懂233</p>
<h1 id="七、结语"><a href="#七、结语" class="headerlink" title="七、结语"></a>七、结语</h1><p>截止到这里，在计算机视觉这条万里长征的道路上，我们可以说已经迈出了伟大的第一步，后面许许多多的图像处理函数，图像算法，还有更加高级的机器学习，卷积神经网络，无不从这里最基础的图像处理工具开始。世上无难事，只怕有心人！继续加油。</p>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>杨大熊
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://yang-da-xiong.gitee.io/2022/01/29/OpenCV%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/" title="OpenCV配置教程">https://yang-da-xiong.gitee.io/2022/01/29/OpenCV配置教程/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Opencv/" rel="tag"># Opencv</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/01/27/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0%E9%A2%9821---%E8%93%9D%E6%A1%A5%E6%9D%AF2019%E7%9C%81%E8%B5%9B%E2%80%9C%E5%90%8E%E7%BC%80%E8%A1%A8%E8%BE%BE%E5%BC%8F%E2%80%9D/" rel="prev" title="算法练习题21---蓝桥杯2019省赛“后缀表达式”">
      <i class="fa fa-chevron-left"></i> 算法练习题21---蓝桥杯2019省赛“后缀表达式”
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/01/29/OpenCV4%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/" rel="next" title="OpenCV配置教程">
      OpenCV配置教程 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%89%8D%E8%A8%80"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E4%B8%8B%E8%BD%BD%E5%92%8C%E5%AE%89%E8%A3%85OpenCV-SDK"><span class="nav-number">2.</span> <span class="nav-text">一、下载和安装OpenCV SDK</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E9%85%8D%E7%BD%AE%E5%8C%85%E5%90%AB%E8%B7%AF%E5%BE%84"><span class="nav-number">3.</span> <span class="nav-text">二、配置包含路径</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E9%85%8D%E7%BD%AE%E5%BA%93%E7%9B%AE%E5%BD%95-amp-%E9%85%8D%E7%BD%AE%E9%93%BE%E6%8E%A5%E5%99%A8"><span class="nav-number">4.</span> <span class="nav-text">三、配置库目录&amp;配置链接器</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="nav-number">5.</span> <span class="nav-text">四、配置环境变量</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81dll%E6%96%87%E4%BB%B6%E5%A4%8D%E5%88%B6%E5%88%B0system32%E4%B8%AD"><span class="nav-number">6.</span> <span class="nav-text">五、dll文件复制到system32中</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AD%E3%80%81%E9%AA%8C%E8%AF%81%E9%85%8D%E7%BD%AE%E7%BB%93%E6%9E%9C"><span class="nav-number">7.</span> <span class="nav-text">六、验证配置结果</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%83%E3%80%81%E7%BB%93%E8%AF%AD"><span class="nav-number">8.</span> <span class="nav-text">七、结语</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="杨大熊"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">杨大熊</p>
  <div class="site-description" itemprop="description">各类IT知识分享</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">58</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Yang-Da-xiong?tab=repositories" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Yang-Da-xiong?tab&#x3D;repositories" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/weixin_45775703?spm=1000.2115.3001.5343" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;weixin_45775703?spm&#x3D;1000.2115.3001.5343" rel="noopener" target="_blank"><i class="fab fa-codiepie fa-fw"></i>CSDN</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">杨大熊</span>
</div>

<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>
</span>
</div>

<span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>

<div class="theme-info">
<div class="powered-by"></div>
<span class="post-count">博客全站共56.5k字</span>
</div>
        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/schemes/clicklove.js"></script>
